#ifndef __TASK_LET__
#define __TASK_LET__

#include <vector>
#include <memory>
#include <unordered_map>
#include "EventTypes.h"

using namespace std;

class Tasklet : public enable_shared_from_this<TaskRootProgressMgrCenter>
{
public:
    Tasklet() = delete;
    Tasklet(unsigned short no = 0, shared_ptr<Tasklet> p = nullptr) : ID(no), m_parentMgr(p)
    {
        if (!m_parentMgr.get())
        {
            // have no parent ,is root mgr
            Root = true;
        }
    }

public:
    shared_ptr<Tasklet> CreateSubTask()
    {
        shared_ptr<Tasklet> psub= make_shared<Tasklet>(unsigned short no, shared_from_this());
        m_subTaskProgress[m_subSize++] = psub;
        return psub;
    }

private:
    /*
    ** init attribute
    */
    bool Root = false;
    unsigned short ID;
    shared_ptr<Tasklet> m_parentMgr = nullptr;
    //??? root_ptr?

private:
    /*
    ** set result event & data
    */
    
    //task class free resource 
    //shared_ptr or ptr?????
    //托管返回的地址或者实例
    void* m_pdata = NULL; 
    EventType m_cbeven = EVE_NULL;

private:
    unsigned short m_subSize = 0;
    unsigned bool m_finished = false;

private:
    unordered_map<unsigned short, shared_ptr<Tasklet>> m_subTaskProgress{};
};

#endif //__TASK_PROGRESSMGR__